﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;

namespace CountLines
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// 应用程序获得焦点的时候触发
        /// </summary>
        /// <param name="e"></param>
        protected override void OnActivated(EventArgs e)
        {
            base.OnActivated(e);

            //MessageBox.Show("OnActivated事件");
        }

        /// <summary>
        /// 应用程序失去焦点的时候触发
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDeactivated(EventArgs e)
        {
            base.OnDeactivated(e);

            //MessageBox.Show("OnDeactivated事件");
        }

        /// <summary>
        /// 应用程序关闭前调用
        /// </summary>
        /// <param name="e"></param>
        protected override void OnExit(ExitEventArgs e)
        {
            base.OnExit(e);

            //MessageBox.Show("OnExit事件");
        }

        /// <summary>
        /// 在调用 Application 对象的 Run 方法时发生。
        /// </summary>
        /// <param name="e"></param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            //MessageBox.Show("OnStartup事件");
            //注册Application_Error
            this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
        }

        /// <summary>
        /// 在用户通过注销或关闭操作系统而结束 Windows 会话时发生。
        /// </summary>
        /// <param name="e"></param>
        protected override void OnSessionEnding(SessionEndingCancelEventArgs e)
        {
            base.OnSessionEnding(e);

            //MessageBox.Show("OnSessionEnding事件");
        }




        /// <summary>
        /// 异常处理逻辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            MessageBox.Show("谁tmd惹祸了:" + e.Exception.Message);
            //处理完后，我们需要将Handler=true表示已此异常已处理过
            e.Handled = true;
        }


    }
}
